
import 'package:json_annotation/json_annotation.dart';

part 'rank_info.g.dart';

@JsonSerializable()
class RankInfo {
  final int code;
  final String message;
  final Data data;

  RankInfo(this.code, this.message, this.data);

  factory RankInfo.fromJson(Map<String, dynamic> json) =>
      _$RankInfoFromJson(json);

  Map<String, dynamic> toJson() => _$RankInfoToJson(this);
}

@JsonSerializable()
class Data {
  final int total;
  final String type;
  final List<RankUser> topUsers;
  final SelfRank self;


  Data(this.total, this.type, this.topUsers, this.self);

  factory Data.fromJson(Map<String, dynamic> json) => _$DataFromJson(json);

  Map<String, dynamic> toJson() => _$DataToJson(this);
}

@JsonSerializable()
class SelfRank{
  final int posIndex;
  final int rankingPos;
  final RankUser userInfo;

  SelfRank(this.posIndex, this.rankingPos, this.userInfo);


  factory SelfRank.fromJson(Map<String, dynamic> json) =>
      _$SelfRankFromJson(json);

  Map<String, dynamic> toJson() => _$SelfRankToJson(this);
}

@JsonSerializable()
class RankUser {
  final int userId;
  final String nickname;
  final String avatarUrl;
  final int vip;
  final int pValue;
  final int rank;
  final int level;


  RankUser(this.userId, this.nickname, this.avatarUrl, this.vip, this.pValue,
      this.rank, this.level);

  factory RankUser.fromJson(Map<String, dynamic> json) =>
      _$RankUserFromJson(json);

  bool get isVip => vip == 1;

  Map<String, dynamic> toJson() => _$RankUserToJson(this);
}
